package com.fanghaoran.view.user.bookFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @Author: win11
 * @Date: 2023/03/18/17:57
 * @Description: 词汇书封面的页面
 */
public class BookCoverPanel extends JPanel {
    /**
     * 书籍编号 用来获取书籍的数据
     */
    public static int bookID;
    /**
     * 四级单词书
     */
    public final static int CET4=4;
    /**
     * 六级单词书
     */
    public final static int CET6=6;
    public BookCoverPanel(){

        //让panel中的组件从左到右排列
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        //垂直box->四级书
        Box vBox1 = Box.createVerticalBox();
        //图标
        ImageIcon im=new ImageIcon("src//image//cet4.jpg");
        //设置图标大小
        im.setImage(im.getImage().getScaledInstance(120,120, Image.SCALE_DEFAULT));
        JLabel cet4Image=new JLabel(im);
        //文字
        JLabel cet4=new JLabel("四级单词书");
        //添加到box
        vBox1.add(cet4Image);
        vBox1.add(cet4);
        //给四级单词书图标添加点击事件 点击就可进入学习
        cet4Image.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                bookID=CET4;
                try {
                    new ModelFrame();
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });

        //垂直box->六级书
        Box vBox2 = Box.createVerticalBox();
        //图标
        ImageIcon im2=new ImageIcon("src//image//cet6.jpg");
        //设置图标大小
        im2.setImage(im2.getImage().getScaledInstance(120,120, Image.SCALE_DEFAULT));
        JLabel cet6Image=new JLabel(im2);
        //文字
        JLabel cet6=new JLabel("六级单词书");
        //添加到box
        vBox2.add(cet6Image);
        vBox2.add(cet6);
        //给六级单词书添加点击事件
        cet6Image.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                bookID=CET6;
                try {
                    new ModelFrame();
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {

            }

            @Override
            public void mouseExited(MouseEvent e) {

            }
        });
        //添加到jPanel
        this.add(vBox1);
        this.add(vBox2);
    }
}
